package com.laycoding.layrpc.common;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.info.InfoProperties;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

@Slf4j
public class LayRpcServiceCache {

    public static ConcurrentHashMap<String, Object> registryMap = new ConcurrentHashMap<>();

    public static Object getService(String name) {

        if (registryMap.containsKey(name)){
            Object obj = registryMap.get(name);
            return obj;
        }

        return null;
    }

    public static void put(String name,Object obj) {
        registryMap.put(name, obj);
    }

    public static List<Class<?>> getAll(){
        List<Class<?>> collect = registryMap.keySet().stream().map(
                s ->  registryMap.get(s).getClass()
        ).collect(Collectors.toList());
        return collect;
    }
}
